<template>
  <div>
    <complex-table :data="rules">
      <el-table-column label="API Groups">
        <template #default="{ row }">
          <div
            v-for="(apiGroup, index) in row.apiGroups"
            :key="index"
            class="myTag"
          >
            <el-tag v-if="apiGroup !== ''" size="small">{{ apiGroup }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="URL">
        <template #default="{ row }">
          <span v-for="(url, index) in row.nonResourceURLs" :key="index">{{
            url
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="Resources" min-width="300px">
        <template #default="{ row }">
          <el-tag
            v-for="(resource, index) in row.resources"
            :key="index"
            type="success"
            >{{ resource }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="Create" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'create')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
      <el-table-column label="Delete" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'delete')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
      <el-table-column label="Get" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'get')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
      <el-table-column label="List" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'list')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
      <el-table-column label="Patch" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'patch')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
      <el-table-column label="Update" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'update')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
      <el-table-column label="Watch" width="80px">
        <template #default="{ row }">
          <i v-if="checkVerb(row.verbs, 'watch')" class="el-icon-check" />
          <span v-else> - </span>
        </template>
      </el-table-column>
    </complex-table>
  </div>
</template>

<script setup lang="ts">
import ComplexTable from "@/views/domain/kubeHud/views/components/complex-table/index.vue";

type Prop = {
  rules: any[];
};
const props = defineProps<Prop>();

const checkVerb = (verbs: string[], ope: string) => {
  return verbs.indexOf("*") > -1
    ? verbs.indexOf("*") > -1
    : verbs.indexOf(ope) > -1;
};
</script>

<style scoped></style>
